from __future__ import with_statement
from subprocess import Popen

import os
import time
import subprocess

time = " -endpos 0:08"

def encoder(path, pipe, media, stream, res, codec):

    if(media == 0):
        print "Video"
        audioOPT = "-oac copy"
        if(stream == "video"):
            audioOPT = "-nosound"
        if(res == "") and (codec == ""):
            subprocess.call("encoder\\util\\mencoder.exe " + path + " " + audioOPT + " -ovc copy -o " + pipe + time)
        elif(res != "") and (codec != ""):
            subprocess.call("encoder\\util\\mencoder.exe " + path + " " + audioOPT + " -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:turbo -vf scale=320:240 -o " + time)
        elif(res != ""):
            subprocess.call("encoder\\util\\mencoder.exe " + path + " " + audioOPT + " -ovc copy -vf scale=320:240 -o " + pipe + time)
        elif(codec != ""):
            subprocess.call("encoder\\util\\mencoder.exe " + path + " " + audioOPT + " -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:turbo -o " + pipe + time)

    elif(media == 1):
        os.system("start encoder\\util\\VLC\\vlc.exe " + path + " :sout=#transcode{acodec=mp3,ab=128,channels=2}:duplicate{dst=std{access=file,mux=ts,dst=" + pipe + "}} -I dummy --dummy-quiet vlc:quit")

    elif(media == 2):
        print "Imagem"
        os.system("start encoder\\util\\image\\convert.exe -quiet " + path + " jpeg:" + pipe)
        print "End"

# encoder



if __name__ == "__main__":
    encoder("entrada.mpg", "saida.asf", 0)